{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from fml_manager import ClusterManager\n",
    "from fml_manager import Party, PartyType"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## For more details about the FMLManager, please refer to this [document](https://kubefate.readthedocs.io/README.html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cluster_manager = ClusterManager(cluster_namespace='fate-10000', cluster_name='fate')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get route table\n",
    "route_table = cluster_manager.get_route_table()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# show all party\n",
    "print(route_table.get_parties())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# delete route table party\n",
    "party_id_1 = '9999'\n",
    "party_id_2 = '8888'\n",
    "route_table.remove_parties(party_id_1, party_id_2)\n",
    "print(route_table.get_parties())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# define normal party\n",
    "party = Party(p_id='9999', ip='192.168.2.2', port=30010)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# append normal party to route table\n",
    "route_table.add_parties(party)\n",
    "print(route_table.get_parties())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# define exchange\n",
    "party = Party(ip='192.168.2.2', port=30009, p_type=PartyType.EXCHANGE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# append exchange to route table\n",
    "route_table.add_parties(party)\n",
    "print(route_table.get_parties())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# update route table of configmap\n",
    "cluster_manager.set_route_table(route_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get entrypoint\n",
    "print(cluster_manager.get_entry_point())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
